// pages/creditCardReset/index.js
import { http } from '../../utils/net.js'
import { inputgetName } from '../../utils/inputBothBind.js'

Page({
  data: {
    bc_id:null,
    cvn2:"",
    effective:"",
    bill:"",
    repayment:"",
    bank_tel:"",
    bank_card:"",
    bank_id:"",
    bankName:"",
    userName:"",
    actionSheetTitle:""
  },
  inputgetName: inputgetName,
  toConfirm() {
    const valueList = Object.values(this.data.params)
    let pass = valueList.every((i) => {
      if(i) {
        return true
      }
    })
    if(!pass) {
      wx.showToast({
        title: '请填写完整',
        icon: 'none',
      })
      return
    }
    http({
      url:"/api/index/index?method=update_credit",
      data: this.data.params,
      isShowLoading: true,
      successCb:(res) => {
        wx.showToast({
          title: res.msg,
          icon: 'success'
        })
        setTimeout(() => {
          wx.navigateBack({
            delta: 1,
          })
        }, 500)
      }
    })
  },
  toResetBankType() {
    // TODO 发卡行
  },
  toResetEffect() {
    // TODO 有效期
  },
  toResetBill() {
    // TODO 账单
    this.setData({
      actionSheetTitle: "请选择账单日"
    })
    this.selectComponent("#daySelect").open()
  },
  toResetRepay() {
    // TODO 还款
    this.setData({
      actionSheetTitle: "请选择还款日"
    })
  },
  onLoad: function (options) {
    let that = this
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('acceptDataFromOpenerPage', function (data) {
      that.setData({
        userName: data.cardInfo.bc_account_name,
        bankName: data.cardInfo.bank_name,
        bc_id: data.cardInfo.bc_id,
        cvn2: data.cardInfo.bc_cvn2,
        effective: data.cardInfo.bc_effective,
        bill: data.cardInfo.bc_bill,
        repayment: data.cardInfo.bc_repayment,
        bank_tel: data.cardInfo.bc_mobile,
        bank_card: data.cardInfo.bc_bank_number,
        bank_id: data.cardInfo.bank_id
      })
    })
  },

  onReady: function () {

  },

  onShow: function () {
    http({
      url: "/api/index/index?method=get_bank_list",
      data: {
        type: 1
      },
      isShowLoading:true,
      successCb:(res) => {

      }

    })
  },

  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})